using System;
using Wilco.SyntaxHighlighting.Engine.Highlighter;
using Wilco.SyntaxHighlighting.Engine.Node.Occurrence;
using Wilco.SyntaxHighlighting.Engine.Parser;
using Wilco.SyntaxHighlighting.Engine.Scanner;
using Wilco.SyntaxHighlighting.Engine.Scanner.Implementation;
using Wilco.SyntaxHighlighting.Engine.Tokenizer;

namespace Wilco.SyntaxHighlighting.Engine.Highlighter.Implementation
{
    /// <summary>
    /// Represents an XML syntax highlighter.
    /// </summary>
    public class XMLHighlighter : HighlighterBase
    {
        /// <summary>
        /// Initializes a new instance of a <see cref="XMLHighlighter"/> class.
        /// </summary>
        public XMLHighlighter() : this(null)
        {
        }

        /// <summary>
        /// Initializes a new instance of a <see cref="XMLHighlighter"/> class.
        /// </summary>
        /// <param name="parser">The parser which will be used to parse the source code.</param>
        public XMLHighlighter(IParser parser) : base(parser)
        {
            Name = "XML";
            FullName = "XML";
            TagValues.AddRange(new String[] { "xml" });
            FileExtensions.AddRange(new String[] { "xml", "html", "htm" });
        }

        /// <summary>
        /// Creates a new instance (clone) of this highlighter.
        /// </summary>
        /// <returns></returns>
        public override HighlighterBase Create()
        {
            return new XMLHighlighter(Parser);
        }

        /// <summary>
        /// Builds a new chain of scanners.
        /// </summary>
        /// <param name="tokenizer">The tokenizer used by the scanners.</param>
        /// <param name="scannerResult">The scanner result.</param>
        /// <returns>
        /// The scanner at the start of the chain.
        /// </returns>
        public override IScanner BuildEntryPointScanner(TokenizerBase tokenizer, OccurrenceCollection scannerResult)
        {
            Tokenizer = tokenizer;
            ScannerResult = scannerResult;

            XmlScanner xmlScanner = new XmlScanner(Tokenizer, ScannerResult);
            return xmlScanner;
        }
    }
}